//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package cn.shengchao.examstarvideo.config;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.feiniaojin.gracefulresponse.data.Response;
import com.feiniaojin.gracefulresponse.data.ResponseStatus;
import com.feiniaojin.gracefulresponse.defaults.DefaultResponseStatus;
import java.util.Objects;


public class Res<T> implements Response {
    private static final ResponseStatus DEFAULT_STATUS_SUCCESS;
    private static final ResponseStatus DEFAULT_STATUS_ERROR;

    private String code;

    private String msg;

    private boolean success;

    private Long timestamp;

    private T data;
    private ResponseStatus status;

    public Res() {
        this.status = new DefaultResponseStatus();
    }

    public Res(ResponseStatus status) {
        this.status = new DefaultResponseStatus();
        this.status = status;
    }

    public Res(String code, String msg) {
        this.status = new DefaultResponseStatus();
        this.setCode(code);
        this.setMsg(msg);
    }

    public Res(ResponseStatus status, T data) {
        this(status);
        this.setData(data);
    }

    public Res(String code, String msg, T data) {
        this(code, msg);
        this.setData(data);
    }

    public void setStatus(ResponseStatus status) {
        this.status = status;
    }

    @JsonIgnore
    public ResponseStatus getStatus() {
        return this.status;
    }

    public void setPayload(Object payload) {
        this.data = (T)payload;
    }

    @JsonIgnore
    public Object getPayload() {
        return this.data;
    }

    public String getCode() {
        return this.status.getCode();
    }

    public void setCode(String code) {
        this.status.setCode(code);
    }

    public String getMsg() {
        return this.status.getMsg();
    }

    public void setMsg(String msg) {
        this.status.setMsg(msg);
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return Objects.equals(DEFAULT_STATUS_SUCCESS.getCode(), this.status.getCode());
    }

    public Long getTimestamp() {
        return System.currentTimeMillis();
    }

    public static Res ok() {
        return new Res(DEFAULT_STATUS_SUCCESS);
    }

    public static Res ok(Object data) {
        return new Res(DEFAULT_STATUS_SUCCESS, data);
    }

    public static Res ok(String msg, Object data) {
        Res res = ok(data);
        res.setMsg(msg);
        return res;
    }

    public static Res fail() {
        return new Res(DEFAULT_STATUS_ERROR);
    }

    public static Res fail(String code, String msg) {
        return new Res(code, msg);
    }

    static {
        DEFAULT_STATUS_SUCCESS =new DefaultResponseStatus();
        DEFAULT_STATUS_ERROR =new DefaultResponseStatus();
    }
}
